public class IsBalanced {

    public boolean isBalanced(TreeNode root) {
        return pocess(root).isBBT;
    }

    public ReturnType pocess(TreeNode node) {
        if (node == null) return new ReturnType(0, true);
        ReturnType left = pocess(node.left);
        ReturnType right = pocess(node.right);

        int heigth = Math.max(left.height, right.height) + 1;
        boolean isBBT = left.isBBT && right.isBBT && Math.abs(left.height - right.height) < 2;
        return new ReturnType(heigth, isBBT);
    }
}

class ReturnType {
    public int height;
    public boolean isBBT;
    public ReturnType(int height , boolean isBBT) {
        this.height = height;
        this.isBBT = isBBT;
    }
}
